
#include "main.h"

// CR - Customer Record 

/* find free entry in Owners or Users List; return Addresd of free entry */
/* int CR_FindFree( unsigned int List ) */
/* { */
/* 	unsigned int Amount, EntryIndex; */
	
/* 	if ( List == LIST_OWNERS ) */
/* 	{ */
/* 		Amount = COUNT_OWNERS; */
/* 	} */
/* 	else */
/* 		if ( List == LIST_USERS_GROUP_1 ) */
/* 		{ */
/* 			Amount = COUNT_USERS;  */
/* 		} */
	
/* 	for ( EntryIndex = 0;  EntryIndex < Amount;  EntryIndex++ ) */
/* 	{ */
/* 		if ( Ex_ReadByte(List) == 0xFF ) */
/* 			return (int)List; */

/* 		List += sizeof(RECORD_CUSTOMER); */
/* 	} */

/* 	return (int)NO_FREE_ENTRY; */
/* } */

/* unsigned char CR_Write( unsigned int Address, RECORD_CUSTOMER* Entry  ) */
/* { */
/* 	return Ex_SaveAndCheck(Address, (unsigned char*)&Entry, sizeof(Entry));  */
/* }  */

 
/* Find Customer Record by Phone Number in the List ; return: Address of the Entry */
/* int CR_Find_ByPhone( unsigned int Address, unsigned char* PhoneNumber ) */
/* { */
/* 	unsigned char i, Phone_BCD[PHONE_NUMBERS_BCD_SIZE]; */
/* 	unsigned int EntryIndex; */

/* 	EX_DIRECTORY_PROPERTIES ListProperties; */

/* 	if ( Ex_Entry_GetDirectoryDescription(Address, &ListProperties) == FALSE ) */
/* 		return (-1);				  /\* ERROR - List(Address) with this Name is not exists *\/ */

/* 	StrToBCD(Phone_BCD, PhoneNumber, PHONE_NUMBERS_BCD_SIZE); */
/* 	FlipFlopN(Phone_BCD, PHONE_NUMBERS_BCD_SIZE); */

/* 	//for ( Address = Address; Address < Amount; Address += sizeof(RECORD_CUSTOMER) ) */
/* 	for ( EntryIndex = 0; EntryIndex < ListProperties.EntryCount; EntryIndex++ ) */
/* 	{ */
/* 		for ( i = 0; i < PHONE_NUMBERS_BCD_SIZE; i++ ) */
/* 		{ */
/* 			if ( Ex_ReadByte(Address + i) != Phone_BCD[i] ) */
/* 				break; */
/* 		} */

/* 		if ( i == PHONE_NUMBERS_BCD_SIZE ) */
/* 			return Address; */

/* 		Address += sizeof(RECORD_CUSTOMER); */
/* 	} */
	
/* 	return (int)NOT_FOUND; */
/* } */

/* /\* Add customer to the List; if the Phone exists - rewrite it; return: No Free Entry or TRUE  *\/ */
/* int CR_Add ( unsigned int ListAddress, unsigned char* PhoneNumber ) */
/* { */
/* 	int Address; */
/* 	RECORD_CUSTOMER Entry; */

/* /\* 	EX_DIRECTORY_PROPERTIES ListProperties; *\/ */

/* /\* 	if ( Ex_Entry_GetDirectoryDescription(Address, &ListProperties) == FALSE ) *\/ */
/* /\* 		return (-1);				  /\\* ERROR - List(Address) with this Name is not exists *\\/ *\/ */
	
/* 	/\*  *\/ */
/* 	unsigned char str[6]; */
/* 	putsf(">>List: ", MODEM_PORT); */
/* 	HexToChar( str, (unsigned char*)&ListAddress, 2); */
/* 	StrCat(str, "\r"); */
/* 	puts(str, MODEM_PORT); */
/* 	/\*  *\/ */
			
/* 	Address = CR_Find_ByPhone( ListAddress, PhoneNumber ); */

/* 	if ( Address == NOT_FOUND ) */
/* 	{ */
/* 		/\*  *\/ */
/* 		putsf(" >>ADRR NOT_FOUND\r", MODEM_PORT); */
/* 		/\*  *\/ */
		
/* 		Address = Ex_Entry_FindFree( ListAddress ); */
/* 		if ( Address == EX_ERROR ) */
/* 		{ */
/* 			/\*  *\/ */
/* 			if ( Ex_Errno == EX_ERROR__NO_FREE_ENTRY ) */
/* 			{ */
/* 				putsf(" >>EX_ERROR: ", MODEM_PORT); */
/* 				puts(LongToStr(str, Ex_Errno), MODEM_PORT); */
/* 				putsf("\r", MODEM_PORT); */
/* 			} */
/* 			/\*  *\/ */
			
/* 			return (int)EX_ERROR; */
/* 		} */
/* 	} */
	
/* 	/\*  *\/ */
/* 	putsf(">>Address: ", MODEM_PORT); */
/* 	HexToChar( str, (unsigned char*)&Address, 2); */
/* 	StrCat(str, "\r"); */
/* 	puts(str, MODEM_PORT); */
/* 	/\*  *\/ */
	
/* 	/\* if the number exists rewrite it*\/ */
/* 	StrToBCD(Entry.Phone, PhoneNumber, PHONE_NUMBERS_BCD_SIZE); */
/* 	FlipFlopN(Entry.Phone, PHONE_NUMBERS_BCD_SIZE); */
/* 	Entry.Reserve = 0xFF; */

/* 	return (int)Ex_SaveAndCheck( Address, (unsigned char*)&Entry, sizeof(Entry));  */
/* 	//return (int)Ex_SaveAndCheck( ListAddress, (unsigned char*)&Entry, sizeof(Entry));  */
/* }  */

/* /\* Delete Customer Record; return: Address of deleted CR if successful, or (-1) if ERROR *\/ */
/* int CR_Delete ( unsigned int List, unsigned char* PhoneNumber ) */
/* { */
/* 	unsigned int Address; */

/* 	Address = CR_Find_ByPhone( List, PhoneNumber ); */
	
/* 	if ( Address == NOT_FOUND ) */
/* 		return (-1); */
	
/* 	if ( Ex_WriteByte(Address, 0xFF) == TRUE ) */
/* 		return Address; */

/* 	return (-1); */
/* } */
 
/* /\* return TRUE if successful *\/ */
/* unsigned char CR_DeleteList( unsigned int List ) */
/* { */
/* 	unsigned int Amount; */

/* 	if ( List == LIST_OWNERS ) */
/* 	{ */
/* 		Amount = COUNT_OWNERS; */
/* 	} */
/* 	else */
/* 		if ( List == LIST_USERS_GROUP_1 ) */
/* 		{ */
/* 			Amount = COUNT_USERS;  */
/* 		} */

/* 	return Ex_MemSet(List, 0xFF, Amount);  */
/* } */

/* return Amount customers in Address or I2C_ERROR*/
/* int CR_Count( unsigned int Address ) */
/* { */
/* 	unsigned int Counter = 0, Amount, EntryIndex; */
/* 	int Result; */

/* 	unsigned char str[8]; */

/* 	if ( Address == LIST_OWNERS ) */
/* 	{ */
/* 		Amount = COUNT_OWNERS; */
/* 	} */
/* 	else */
/* 		if ( Address == LIST_USERS_GROUP_1 ) */
/* 		{ */
/* 			Amount = COUNT_USERS;  */
/* 		} */

/* 	for ( EntryIndex = 0;  EntryIndex < Amount;  EntryIndex++ ) */
/* 	{ */
/* 		//Ex_LoadFrom(str, Address, 8); */
/* 		Result = Ex_ReadByte( Address ); */
/* 		//Result = str[0]; */
/* 		LongToStr(str, Result); */
/* 		puts(str, MODEM_PORT); */
/* 		putsf("\r", MODEM_PORT); */
		
/* 		if ( Result == I2C_ERROR ) */
/* 			return I2C_ERROR; */
		
/* 		if ( Result != 0xFF ) */
/* 			Counter++; */
		
/* 		Address += sizeof(RECORD_CUSTOMER); */
/* 	} */

/* 	return (int)Counter; */
/* } */




/* ========================================================
	unsigned char str[4];

	//Address = Address;
	LongToStr(str, Address);
	puts(str, MODEM_PORT);
	putsf(PhoneNumber, MODEM_PORT);
	putsf("\r", MODEM_PORT);


	=================

	if ( Ex_SaveAndCheck( Address, (unsigned char*)&Entry, sizeof(Entry)) )
	{
		putsf("TRUE", MODEM_PORT);
		return TRUE;
	}
	else
		return FALSE;



17:45:52:978> >>S_Manager
17:45:52:994> 52
17:45:52:994> 255
17:45:53:009> 255
17:45:53:009> 255
17:45:53:025> 255
17:45:53:025> 255
17:45:53:025> 255
17:45:53:041> 255
17:45:53:041> 255
17:45:53:041> 255
17:45:53:056> 255
17:45:53:056> 255
17:45:53:056> 255
17:45:53:056> 255
17:45:53:072> 255
17:45:53:072> 255
17:45:53:072> 255
17:45:53:072> 255
17:45:53:088> 255
17:45:53:088> 255
17:45:53:088> 52
17:45:53:103> 255
17:45:53:103> 255
17:45:53:103> 255
17:45:53:103> 255
17:45:53:119> 255
17:45:53:119> 255
17:45:53:119> 255
17:45:53:119> 255
17:45:53:134> 255
17:45:53:134> 255
17:45:53:134> 255
17:45:53:150> 255
17:45:53:150> 255
17:45:53:150> 255
17:45:53:150> 255
17:45:53:166> 255
17:45:53:166> 255
17:45:53:166> 255
17:45:53:166> 255
17:45:53:181> AT+CMGS="0525620534",129


 */
